import 'package:ca_dsp_pro/src/tool/assets.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

class DbItem extends StatefulWidget {
  String name;
  double max;
  double min;
  double value;
  bool ison;
  double radius = 3;
  void Function(double value, bool issend)? onChanged;
  void Function(bool)? onTurnOn;
  DbItem(
      {super.key,
      required this.name,
      required this.max,
      required this.min,
      required this.value,
      required this.ison,
      this.radius = 3,
      required this.onChanged,
      required this.onTurnOn});

  @override
  State<DbItem> createState() => _DbItemState();
}

class _DbItemState extends State<DbItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Color_bg_view2, borderRadius: BorderRadius.circular(widget.radius)),
      padding: const EdgeInsets.only(top: 5, left: 5, right: 5, bottom: 5),
      child: Column(spacing: 5, children: [
        Container(
          height: 20,
          child: Center(
            child: FittedBox(
              fit: BoxFit.scaleDown,
              child: Text(widget.name),
            ),
          ),
        ),
        Expanded(
          child: Container(
            color: Color_bar,
            child: kSlider(
              dirction: Axis.horizontal,
              value: widget.value,
              min: widget.min,
              max: widget.max,
              onChanged: (currentValue) => widget.onChanged?.call(currentValue, false),
              onChangedForSend: (currentValue) => widget.onChanged?.call(currentValue, true),
            ),
          ),
        ),
        Container(
          color: Color_border,
          height: 30,
          child: Center(
            child: Text('${widget.value}'),
          ),
        ),
        Container(
          color: Color_border,
          height: 30,
          child: Material(
            color: Colors.transparent,
            child: InkWell(
                child: Center(
                  child: Image.asset(widget.ison ? assets.voice_on : assets.voice_off),
                ),
                onTap: () => widget.onTurnOn?.call(!widget.ison)),
          ),
        )
      ]),
    );
  }
}
